import {DictOptions} from "@/utils/common-types";

import {getDictOptions} from "@/api/sys/admin/dict";


function getDictWithCode(code: string): Promise<DictOptions[]> {
    return new Promise((resolve) => {
        const statusOptions = [
            {
                name: '正常',
                code: 1
            }, {
                name: '禁用',
                code: 0
            }
        ]
        const genderOptions = [
            {
                name: '男',
                code: 1
            }, {
                name: '女',
                code: 2
            }
        ]
        if (code === 'status') {
            // setTimeout(resolve, 0, statusOptions)
            resolve(statusOptions)
        } else {
            // setTimeout(resolve, 0, genderOptions)
            resolve(genderOptions)
        }

    })
}

/**
 * 格式化Table,返回名称
 * 传入当前值,和选项
 * @param value
 * @param options
 */
export function commonFormat(value: number, options: DictOptions[]): string | undefined {
    return options.find(item => item.code === value)?.name;
}

/**
 * 传入code,得到promises
 * @param codes
 */
export function commonGetOptions(...codes: string[]) {
   return codes.map(item => getDictOptions(item))
}
